package com.example.pei.ithinklearnt.bean;

import android.text.TextUtils;

import com.example.pei.ithinklearnt.Config;
import com.example.pei.ithinklearnt.db.NewComment;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.bmob.newim.bean.BmobIMExtraMessage;
import cn.bmob.newim.bean.BmobIMMessage;

import static com.example.pei.ithinklearnt.utils.MyUtils.getSendTime;

/**
 * 别人评论了动态的通知
 * Created by Pei on 2018/4/14.
 */

public class AddCommentMessage extends BmobIMExtraMessage {

    public static final String COMMENT = "comment";

    private String fromUsername;   //谁回复的你
    private String fromAvatar;     //回复你的人头像
    private String commentId;      //评论的回复

    @Override
    public String getMsgType() {
        return COMMENT;
    }

    @Override
    public boolean isTransient() {
        //设置为true,表明为暂态消息，那么这条消息并不会保存到本地db中，SDK只负责发送出去
        //设置为false,则会保存到指定会话的数据库中
        return true;
    }

    /**
     * 把 BmobIMMessage 转换为  AddCommentMessage
     * @param msg
     * @return
     */
    public static NewComment convert(BmobIMMessage msg) {
        NewComment add = new NewComment();
        //String content = msg.getContent();

        add.setTime(msg.getCreateTime());
        add.setStatus(Config.STATUS_VERIFY_NONE);
        try {
            String extra = msg.getExtra();
            if (!TextUtils.isEmpty(extra)) {
                JSONObject json = new JSONObject(extra);
                String name = json.getString("name");
                add.setFromUsername(name);
                String id = json.getString("id");
                add.setId(id);
                String avatar = json.getString("avator");
                add.setAvactor(avatar);
                String contentt = json.getString("content");
                add.setContent(contentt);
                String bContentt=json.getString("bcontent");
                add.setbContent(bContentt);

            } else {

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return add;
    }



    public AddCommentMessage(){

    }

    public String getFromAvatar() {
        return fromAvatar;
    }

    public void setFromAvatar(String fromAvatar) {
        this.fromAvatar = fromAvatar;
    }

    public String getFromUsername() {
        return fromUsername;
    }

    public void setFromUsername(String fromUsername) {
        this.fromUsername = fromUsername;
    }

    public String getCommentId() {
        return commentId;
    }

    public void setCommentId(String commentId) {
        this.commentId = commentId;
    }

}
